package com.ruoyi.web.controller.combat.useralignment;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.combat.domain.useralignment.CombatHeavyUser;
import com.ruoyi.combat.service.useralignment.ICombatHeavyUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 重保用户Controller
 * 
 * @author ruoyi
 * @date 2025-03-14
 */
@RestController
@RequestMapping("/cmobat/heavyUser")
@Api(tags = "课题五：重保用户")
public class CombatHeavyUserController extends BaseController
{
    @Autowired
    private ICombatHeavyUserService combatHeavyUserService;

    /**
     * 查询重保用户列表
     */
    @ApiOperation(value = "查询重保用户列表")
    @PreAuthorize("@ss.hasPermi('cmobat:heavyUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(CombatHeavyUser combatHeavyUser)
    {
        startPage();
        List<CombatHeavyUser> list = combatHeavyUserService.selectCombatHeavyUserList(combatHeavyUser);
        return getDataTable(list);
    }

    /**
     * 导出重保用户列表
     */
    @ApiOperation("导出重保用户列表")
    @PreAuthorize("@ss.hasPermi('cmobat:heavyUser:export')")
    @Log(title = "重保用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CombatHeavyUser combatHeavyUser)
    {
        List<CombatHeavyUser> list = combatHeavyUserService.selectCombatHeavyUserList(combatHeavyUser);
        ExcelUtil<CombatHeavyUser> util = new ExcelUtil<CombatHeavyUser>(CombatHeavyUser.class);
        util.exportExcel(response, list, "重保用户数据");
    }

    /**
     * 获取重保用户详细信息
     */
    @ApiOperation("获取重保用户详细信息")
    @PreAuthorize("@ss.hasPermi('cmobat:heavyUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(combatHeavyUserService.selectCombatHeavyUserById(id));
    }

    /**
     * 新增重保用户
     */
    @ApiOperation("新增重保用户")
    @PreAuthorize("@ss.hasPermi('cmobat:heavyUser:add')")
    @Log(title = "重保用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CombatHeavyUser combatHeavyUser) throws IOException {
        return toAjax(combatHeavyUserService.insertCombatHeavyUser(combatHeavyUser));
    }

    /**
     * 修改重保用户
     */
    @ApiOperation("修改重保用户")
    @PreAuthorize("@ss.hasPermi('cmobat:heavyUser:edit')")
    @Log(title = "重保用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CombatHeavyUser combatHeavyUser)
    {
        return toAjax(combatHeavyUserService.updateCombatHeavyUser(combatHeavyUser));
    }

    /**
     * 删除重保用户
     */
    @ApiOperation("删除重保用户")
    @PreAuthorize("@ss.hasPermi('cmobat:heavyUser:remove')")
    @Log(title = "重保用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(combatHeavyUserService.deleteCombatHeavyUserByIds(ids));
    }

    @ApiOperation("检测用户信息是否存在风险")
    @GetMapping("/detect/{ids}")
    public AjaxResult detect(@PathVariable Long[] ids){
        return AjaxResult.success(combatHeavyUserService.detect(ids));
    }
    @ApiOperation("检测所有用户信息是否存在风险")
    @GetMapping("/detectAll")
    public AjaxResult detectAll(){
        return AjaxResult.success(combatHeavyUserService.detectAll());
    }
}
